package com.mdd.admin.controller.client;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IClientCaseService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.ClientCaseCreateValidate;
import com.mdd.admin.validate.ClientCaseUpdateValidate;
import com.mdd.admin.validate.ClientCaseSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.ClientCaseListedVo;
import com.mdd.admin.vo.ClientCaseDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/clientCase")
@Api(tags = "客户案件管理")
public class ClientCaseController {

    @Resource
    IClientCaseService iClientCaseService;

    @GetMapping("/list")
    @ApiOperation(value="客户案件列表")
    public AjaxResult<PageResult<ClientCaseListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated ClientCaseSearchValidate searchValidate) {
        PageResult<ClientCaseListedVo> list = iClientCaseService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="客户案件详情")
    public AjaxResult<ClientCaseDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        ClientCaseDetailVo detail = iClientCaseService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "客户案件新增")
    @PostMapping("/add")
    @ApiOperation(value="客户案件新增")
    public AjaxResult<Object> add(@Validated @RequestBody ClientCaseCreateValidate createValidate) {
        iClientCaseService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户案件编辑")
    @PostMapping("/edit")
    @ApiOperation(value="客户案件编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody ClientCaseUpdateValidate updateValidate) {
        iClientCaseService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户案件删除")
    @PostMapping("/del")
    @ApiOperation(value="客户案件删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iClientCaseService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
